package cn.tedu.lbs.basic.web.controller;

import cn.tedu.lbs.basic.web.service.AreaService;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.pojo.basic.vo.AreaVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class AreaController {
    //查询 省级列表 入参是空 控制层 赋值0
    @Autowired
    private AreaService areaService;
    @GetMapping("/admin/basic/area/queryList")
    public Result<List<AreaVO>> provinceList(){
        //业务数据 parentId=0 在控制层补充
        Integer parentId=0;
        return new Result<>(areaService.getChildren(parentId));
    }
    //查询 省 市 下一级行政区区域
    @GetMapping("/admin/basic/area/{parentId}/children")
    public Result<List<AreaVO>> childrenList(@PathVariable(value = "parentId") Integer parentId){
        return new Result<>(areaService.getChildren(parentId));
    }

    //查询所有行政区域数据 组织三级树状结构
    @GetMapping("/admin/basic/area/tree")
    public Result<List<AreaVO>> tree(){
        return new Result<>(areaService.tree());
    }
}
